package com.fsnbigdata.service.impl;
import com.fsnbigdata.service.api.ListQuadratService;
import org.springframework.roo.addon.layers.service.annotations.RooServiceImpl;
import com.fsnbigdata.domain.ListQuadrat;
import com.fsnbigdata.domain.ListQuadratItem;
import com.fsnbigdata.domain.Vegetation;
import com.fsnbigdata.repository.ListQuadratRepository;
import com.fsnbigdata.service.api.ListQuadratItemService;
import io.springlets.data.domain.GlobalSearch;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * = ListQuadratServiceImpl
 *
 * TODO Auto-generated class documentation
 *
 */
@RooServiceImpl(service = ListQuadratService.class)
@Service
@Transactional(readOnly = true)
public class ListQuadratServiceImpl implements ListQuadratService {

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    private ListQuadratRepository listQuadratRepository;

    /**
     * TODO Auto-generated attribute documentation
     *
     */
    private ListQuadratItemService listQuadratItemService;

    /**
     * TODO Auto-generated constructor documentation
     *
     * @param listQuadratRepository
     * @param listQuadratItemService
     */
    @Autowired
    public ListQuadratServiceImpl(ListQuadratRepository listQuadratRepository, @Lazy ListQuadratItemService listQuadratItemService) {
        setListQuadratRepository(listQuadratRepository);
        setListQuadratItemService(listQuadratItemService);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return ListQuadratRepository
     */
    public ListQuadratRepository getListQuadratRepository() {
        return listQuadratRepository;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param listQuadratRepository
     */
    public void setListQuadratRepository(ListQuadratRepository listQuadratRepository) {
        this.listQuadratRepository = listQuadratRepository;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return ListQuadratItemService
     */
    public ListQuadratItemService getListQuadratItemService() {
        return listQuadratItemService;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param listQuadratItemService
     */
    public void setListQuadratItemService(ListQuadratItemService listQuadratItemService) {
        this.listQuadratItemService = listQuadratItemService;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param listQuadrat
     * @param itemsToAdd
     * @return ListQuadrat
     */
    @Transactional
    public ListQuadrat addToItems(ListQuadrat listQuadrat, Iterable<ListQuadratItem> itemsToAdd) {
        listQuadrat.addToItems(itemsToAdd);
        return getListQuadratRepository().save(listQuadrat);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param listQuadrat
     * @param itemsToRemove
     * @return ListQuadrat
     */
    @Transactional
    public ListQuadrat removeFromItems(ListQuadrat listQuadrat, Iterable<Long> itemsToRemove) {
        List<ListQuadratItem> items = getListQuadratItemService().findAll(itemsToRemove);
        listQuadrat.removeFromItems(items);
        return getListQuadratRepository().save(listQuadrat);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param entity
     * @return ListQuadrat
     */
    @Transactional
    public ListQuadrat save(ListQuadrat entity) {
        return getListQuadratRepository().save(entity);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param id
     * @return ListQuadrat
     */
    public ListQuadrat findOne(Long id) {
        return getListQuadratRepository().findOne(id);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param id
     * @return ListQuadrat
     */
    public ListQuadrat findOneForUpdate(Long id) {
        return getListQuadratRepository().findOneDetached(id);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param ids
     * @return List
     */
    public List<ListQuadrat> findAll(Iterable<Long> ids) {
        return getListQuadratRepository().findAll(ids);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param vegetation
     * @param globalSearch
     * @param pageable
     * @return Page
     */
    public Page<ListQuadrat> findByVegetation(Vegetation vegetation, GlobalSearch globalSearch, Pageable pageable) {
        return getListQuadratRepository().findByVegetation(vegetation, globalSearch, pageable);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @param vegetation
     * @return Long
     */
    public long countByVegetation(Vegetation vegetation) {
        return getListQuadratRepository().countByVegetation(vegetation);
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Class
     */
    public Class<ListQuadrat> getEntityType() {
        return ListQuadrat.class;
    }

    /**
     * TODO Auto-generated method documentation
     *
     * @return Class
     */
    public Class<Long> getIdType() {
        return Long.class;
    }
}
